﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : webapp4U.UI.BasePage
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
       dt = new ClassExecute.ClassExecute();
       string kq = "notauthentication";
        try
        {
            kq = dt.GetDataDepend(str, "k_checkLogin", CommandType.StoredProcedure, ref error,
               new SqlParameter("@UserName", txtUser.Text),
               new SqlParameter("@Password", dt.GetMd5Sum(txtPass.Text)));
          
            if ((kq != "notauthentication")&&(kq!=""))
            {
                Session["user"] = txtUser.Text;
                Session["UserType"] = kq;
                Session["sitecode"] = dt.GetDataDepend(str, "k_getSiteCodeByUser", CommandType.StoredProcedure, ref error,
                    new SqlParameter("@UserName", txtUser.Text));
                Response.Redirect(webapp4U.Globals.ApplicationPath + "Pages/Management/Default.aspx", true);
            }
            else
            {
                uscMsgBox1.AddMessage("Tài khoản không hợp lệ", uscMsgBox.enmMessageType.Attention);
            }
        }
        catch(Exception ex)
        {
            
           
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            dt.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);     
        }
    }
}